from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest



def send_sms_code(mobile,sms_code):
    # sms_code = '%06d' % random.randint(1000, 9999)

    client = AcsClient('LTAI5tSQpTmiCiHfS7Y9Uyr7', 'nwQ89UAnT0YsK0ib8poLIfBsC6GiVD', 'cn-hangzhou')

    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')  # https | http
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', mobile)
    request.add_query_param('SignName', "阿里云短信测试")
    request.add_query_param('TemplateCode', "SMS_154950909")
    request.add_query_param('TemplateParam', {'code': sms_code})
    response = client.do_action_with_exception(request)

    print(str(response, encoding='utf-8'))
    return sms_code
